﻿using LoveEat.API.Read.Applications.Commands.Deep;
using LoveEat.Domain.Deep;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;

namespace LoveEat.API.Read.Applications.CommandHandlers.Deep
{
    public class DeepQueryCommandHandler : IRequestHandler<DeepQueryCommand, APIResult<List<DeepModel>>>
    {
        private readonly IBaseRespository<DeepModel> deepRep;

        public DeepQueryCommandHandler(IBaseRespository<DeepModel> deepRep)
        {
            this.deepRep = deepRep;
        }

        public Task<APIResult<List<DeepModel>>> Handle(DeepQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<DeepModel>> result=new APIResult<List<DeepModel>>();
            result.Code=APIResultCode.查询成功;
            result.Message=APIResultCode.查询成功.ToString();



            var res = deepRep.GetAll().ToList();
            res = res.OrderByDescending(x => x.DeepId).ToList();
            result.Data= res;




            return Task.FromResult(result);
        }
    }
}
